<template>
  <el-dialog v-model="openDialog" @closed="handleClose" title="条件设置" width="850px">
    <el-input v-model="conditionContent" placeholder="" type="textarea" :autosize="{ minRows: 3, maxRows: 5 }" />
    <div class="tips-btn-area">
      <div>双击选择数据域到公示框</div>
      <el-button @click="conditionContent = ''">重置</el-button>
    </div>
    <div class="bottom_area">
      <div style="width: 60%">
        <el-tabs v-model="activeName" class="demo-tabs" @tab-click="handleClick">
          <el-tab-pane v-for="item in tabsList" :label="item.label" :name="item.name">
            <div class="card-list">
              <el-card class="box-card">
                <el-input v-model="tabSearchInput" class="w-25" placeholder="Please Input">
                  <template #prefix>
                    <el-icon class="el-input__icon">
                      <search />
                    </el-icon>
                  </template>
                </el-input>
                <div class="condition_list">
                  <div v-for="(item, index) in conditionArray" :key="index" @click="conditionItemChoose(item)">
                    <span>{{ item.label }}</span>
                  </div>
                </div>
              </el-card>
            </div>
          </el-tab-pane>
        </el-tabs>
      </div>
      <div class="btn-area">
        <el-button type="primary" plain v-for="(item, index) in calcArray" :key="'calc_' + index" class="calc-btn" :style="{
          width:
            item.size == 'large'
              ? '29%'
              : item.size == 'middle'
                ? '20%'
                : '10%'
        }" @click="calcBtnFun(item)">{{ item.label }}</el-button>
      </div>
    </div>

    <template #footer>
      <el-button type="primary" @click="confirm">确定</el-button>
    </template>
  </el-dialog>

  <el-dialog v-model="innerVisible" width="28%" :title="innerTitle" append-to-body @closed="innerHandleClose">
    <el-form :model="innerFormData" label-width="120px" status-icon>
      <el-form-item label="表单域" prop="name">
        <el-input v-model="innerFormData.name" style="width: 300px" />
      </el-form-item>
      <el-form-item label="操作符" prop="region">
        <el-input v-model="innerFormData.name" style="width: 300px" />
      </el-form-item>
      <el-form-item label="" prop="region">
        <el-input v-model="innerFormData.name" style="width: 300px" @focus="openJobsCom" />
        <el-radio-group v-model="radio" class="innerFormRadio">
          <el-radio :label="3">值</el-radio>
          <el-radio :label="6" class="formYu">表单域</el-radio>
        </el-radio-group>
      </el-form-item>
      <el-form-item label="" prop="region">
        <el-input v-model="innerFormData.name" style="width: 300px" />
      </el-form-item>
    </el-form>
    <template #footer>
      <el-button type="primary" @click="innerComfirm">确定</el-button>
      <el-button @click="innerHandleClose">取消</el-button>
    </template>
  </el-dialog>
  <jobsTreeTransfer ref="jobsTreeCom" :isMulti="true" :isEmployee="true" :isMix="true" @submit="jobsComSubmit" />
</template>

<script>
import { calcArray, organizationList } from "./calcData";
import jobsTreeTransfer from "@/components/jobsTreeTransfer";
export default {
  name: "conditionSettingDialog",
  components: {
    jobsTreeTransfer
  },
  props: {},
  data () {
    return {
      organizationList,
      conditionArray: [],
      openDialog: false,
      conditionContent: "",
      tabsList: [
        {
          label: "组织架构变量",
          name: "1"
        },
        {
          label: "日期变量",
          name: "2"
        }
      ],
      activeName: "",
      tabSearchInput: "",
      calcArray,
      innerVisible: false,
      innerTitle: "",
      innerFormData: {},
      curBtnObj: null,
      radio: ""
    };
  },

  methods: {
    onChangeVisible () {
      this.openDialog = true;
    },
    confirm () {
      this.innerTitle = this.curBtnObj.label + "配置";
      this.innerVisible = true;
    },
    calcBtnFun (item) {
      this.curBtnObj = item;
      this.conditionContent += item.value;
    },
    conditionItemChoose (item) {
      this.conditionContent += item.value;
    },
    innerComfirm () { },
    innerHandleClose () {
      this.innerVisible = false;
    },
    openJobsCom () {
      this.innerVisible = false;
      this.$refs.jobsTreeCom.onChangeVisible();
    },
    jobsComSubmit () {
      this.innerVisible = true;
    }
  },

  mounted () {
    this.activeName = this.tabsList[0].name;
    this.conditionArray = this.organizationList;
  }
};
</script>

<style lang="scss" scoped>
.tips-btn-area {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin: 14px 8px 4px 8px;
}

.card-list {
  display: flex;
  width: 100%;
  justify-content: space-evenly;
  align-items: center;
}

.box-card {
  width: 100%;
  height: 380px;

  .condition_list {
    overflow-y: auto;
    display: flex;
    flex-direction: column;
    margin-top: 8px;
    height: 300px;

    div {
      margin: 2px 8px 2px 0px;
      padding: 2px;
      cursor: pointer;
      border-radius: 2px;
    }

    div:hover {
      background-color: #f1f5ff;
    }
  }
}

.bottom_area {
  display: flex;

  .btn-area {
    width: 40%;
    height: 380px;
    margin-top: 57px;
    margin-left: 20px;

    .calc-btn {
      margin-bottom: 5%;
    }

    .calc-btn:first-child {
      margin-left: 12px;
    }
  }
}

.innerFormRadio {
  position: absolute;
  left: -50px;

  .formYu {
    position: absolute;
    top: 50px;
    left: -28px;
  }
}
</style>
